package com.boot;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.context.WebApplicationContext;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

@SpringBootApplication
@ComponentScan({"com.config","com.service","com.task",
        "com.api","com.action","com.listerner"
     })
@MapperScan({"com.dao"})
@ImportResource("classpath:spring-transaction.xml") 
@ServletComponentScan(basePackages = "com.listener")
@EnableScheduling
@EnableAsync
public class MainBoot extends SpringBootServletInitializer {


    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream(new File( "ip.properties")));
            System.getProperties().putAll(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
         return application.sources(MainBoot.class);
    }

    public static void main(String[] args) {
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream(new File( "ip.properties")));
            System.getProperties().putAll(properties);
        } catch (Exception e) {
            System.out.println("缺少ip.properties文件");
        }

        try {
            properties.load(new FileInputStream(new File( "settings.properties")));
            System.getProperties().putAll(properties);
        } catch (Exception e) {

        }
       ConfigurableApplicationContext applicationContext =  SpringApplication.run(MainBoot.class);

    }
}
